import { getUserInfo } from '../store/state/actions';
import { IntentionParams, ResultData } from '../types';
import { IntentionFormState } from '../types/form.interface';
import request from '/@/utils/request';

enum Api {
  user = '/user',
  intention = '/intention',
  participator = '/participator',
}

export function getAccessToken(code: string, testAuth: number = 0): Promise<unknown> {
  const params = {
    code,
    testAuth,
  };
  return request({
    url: `${Api.user}/auth`,
    method: 'get',
    params,
  });
}

export function getUser(): Promise<unknown> {
  return request({
    url: `${Api.user}/getUser`,
    method: 'get',
  });
}

export function createIntention(data: IntentionFormState): Promise<unknown> {
  return request({
    url: Api.intention,
    method: 'post',
    data,
  });
}

export function getIntentionlist(): Promise<unknown> {
  return request({
    url: Api.intention,
    method: 'get',
  });
}

export function getIntention(params: IntentionParams): Promise<unknown> {
  return request({
    url: `${Api.intention}/${params.uuid}`,
    method: 'get',
  });
}

export function joinIntention(id: number | undefined) {
  if (!id) return;
  return request({
    url: `${Api.participator}`,
    method: 'post',
    data: { intention: { id } },
  });
}
